package com.efesco.payroll.payrollClass;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;
import com.bstek.dorado.common.rtexpr.impl.ExpressionUtils;
import com.efesco.common.DBTools;
import com.efesco.common.Tools;
import com.efesco.system.User;

/**
 * SelectClass_datasetPayClassListener
 */
public class SelectClass_datasetPayClassListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset) throws Exception {
	  DoradoContext context = DoradoContext.getContext();
	  SqlDataset ds=(SqlDataset)dataset;
	  User user=(User)context.getAttribute(context.SESSION,"User");
  
	  String sql="select wc.WA_CLASS_ID,wc.WA_CLASS_NAME,wc.SEND_DAY,wc.SINGLE_COMPANY_ID,"
		  +"com.company_code,com.company_chinese_name "
		  +"from s_wa_class wc,s_single_company com "
		  +"where wc.single_company_id=com.single_company_id and wc.dr=0 and (wc.is_template is null or wc.is_template=0) "
		  +"and com.single_company_id in"+DBTools.getRightSqlByCom(user.getForEmployeeId(),"com")+" ";    
	  
	  String className=Tools.toStr(ds.parameters().getString("wa_class_name"));
	  if(!"".equals(className)){
		  sql+=" and wc.WA_CLASS_NAME like '%"+className+"%' ";
	  }
	  String comName=Tools.toStr(ds.parameters().getString("company_chinese_name"));
	  if(!"".equals(comName)){
		  sql+=" and com.company_chinese_name like '%"+comName+"%' ";
	  }
	  ds.setSql(sql);	
      return true;
  }

  public void afterLoadData(Dataset dataset)
     throws Exception {

  }

}
